#include "StdAfx.h"
#include "ClipManager.h"

CClipManager::CClipManager(void)
{
}

CClipManager::~CClipManager(void)
{
}
void CClipManager::SetClipboard(HWND h_wnd,CString &str)
{
	if(OpenClipboard(h_wnd))
	{
		TCHAR *strAux = str.GetBuffer();
		int isize = str.GetLength()+1;
		EmptyClipboard();
		HGLOBAL h_mem = GlobalAlloc(GMEM_DDESHARE,isize*sizeof(TCHAR));
		if(h_mem)
		{
			LPTSTR data = (TCHAR *)GlobalLock(h_mem);
			memcpy(data,strAux,isize*sizeof(TCHAR));
			SetClipboardData(CF_UNICODETEXT,h_mem);
			GlobalUnlock(h_mem);
		}
		CloseClipboard();
	}
}
void CClipManager::GetClipboard(HWND h_wnd, CString &str)
{
	if(OpenClipboard(h_wnd))
	{
		HANDLE h_hnd = GetClipboardData(CF_TEXT);
		char *data = (char*)GlobalLock(h_hnd);
		str = data;
		GlobalUnlock(h_hnd);
		CloseClipboard();
	}
}